




<?php echo APP;?>


<?php
global $aux;
$aux = 1;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('posts_per_page=-1'.'&paged='.$paged); 
while ($wp_query->have_posts()) : $wp_query->the_post();
    //$key = get_post_meta($post->ID, 'bloco', true);
    //if($key == '1' || $key == '2' || $key == '3') { 
    
    if ( in_category( 'noticias' ) ) {
	
    	if ($aux == 1) { ?>
			<div style="width: 650px; height: 280px; margin: auto;">
				<div style="width: 300px; float: left;">
					<p>
					<a href="<?php the_permalink(); ?>"	title="<?php the_title_attribute();?>"><?php the_title();?></a>
					<?php the_excerpt(); ?>
				    </p>
				</div>
    	<?php $aux = $aux+1; 	
    	}
    	elseif ($aux == 2) { ?>
				<div style="width: 300px; float: right;">
					<p>
					<a href="<?php the_permalink(); ?>"	title="<?php the_title_attribute();?>"><?php the_title();?></a>
					<?php the_excerpt(); ?>
					</p>
				</div>
		</div>
		<?php $aux = 1;
 
        }?>
        
    <?php    
    } else { 
		// Do nothing 
	}
endwhile; 


?>
<br />
<br />
<br />
<br />
<br />
<br />

<br />
<br />
<br />
<br />
<br />
<br />

<br />
<br />
<br />
<br />
<br />
<br />


<?php 
include_once ABSPATH.'/av-define.php';
include_once PDO.'/MembroPDO.class.php';

$us = new MembroPDO();
$linha = $us->busca_membro();
$aux = 0;



foreach ($linha as $key) {
	//echo utf8_encode($key['nome']) . "<br>\n";
	//echo utf8_encode($key['email']) . "<br>\n";
	
	$aux = $aux + 1;
	
	$st = utf8_encode($key['nome']);
	
	$p = explode(" ", $st);
	$total = count($p);
	
	
	//Traz dados do banco
	$login = retira_acentos(strtolower_utf8($p[0])).retira_acentos(strtolower_utf8($p[$total - 1]));
	$senha = generatePassword(8);
	$nome  = ucfirst(strtolower_utf8($p[0]));
	$sobre_nome = ucfirst(strtolower_utf8($p[$total - 1]));
	$email = utf8_encode($key['email']);
	$telefone = utf8_encode($key['telefone']);
	$fax = utf8_encode($key['fax']);
	$morada = utf8_encode($key['morada']); 
	$cod_postal = utf8_encode($key['cod_postal']);
	$concelho = utf8_encode($key['descricao']);
	$localidade = utf8_encode($key['localidade']);
	$url = utf8_encode($key['url']);
	$conteudo = utf8_encode($key['conteudo']);
	$stam = utf8_encode($key['stam']);
	$clube = utf8_encode($key['clube']);
	$clube2 = utf8_encode($key['clube2']);
	$cluble3 = utf8_encode($key['clube3']);
	$data = utf8_encode($key['data']);
	$activo = utf8_encode($key['activo']);
	$user_role = 'contributor';
	
	echo 'Criador:    '.$st.'<br>';
	echo 'login:      '.$login.'<br>';
	echo 'senha:      '.$senha.'<br>';
	echo 'nome:       '.$nome.'<br>';
	echo 'sobre nome: '.$sobre_nome.'<br>';
	echo 'email:      '.$email.'<br>';
	echo 'telefone:   '.$telefone.'<br>';
	echo 'fax:        '.$fax.'<br>';
	echo 'morada:     '.$morada.'<br>';
	echo 'cod postal: '.$cod_postal.'<br>';
	echo 'concelho:   '.$concelho.'<br>';
	echo 'localidade: '.$localidade.'<br>';
	echo 'url:        '.$url.'<br>';
	echo 'conteudo:   '.$conteudo.'<br>';
	echo 'stam:       '.$stam.'<br>';
	echo 'clube:      '.$clube.'<br>';
	echo 'clube2:     '.$clube2.'<br>';
	echo 'clube3:     '.$clube3.'<br>';
	echo 'data:       '.$data.'<br>';
	echo 'activo:     '.$activo.'<br>';
	
	
	//Cria page
	$new_page = array(
			'slug' => $nome.$sobre_nome,
			'title' => $nome.' '.$sobre_nome,
			'content' => ""
	);
	$new_page_id = wp_insert_post( array(
			'post_title'     => $new_page['title'],
			'post_type' 	 => 'page',
			'post_name'	     => $new_page['slug'],
			'comment_status' => 'closed',
			'ping_status'    => 'closed',
			'post_content'   => $new_page['content'],
			'post_status'    => 'publish',
			'post_author'    => 1,
			'menu_order'     => 0
	));

	//Faz hierarquia
	add_post_meta($new_page_id, '_wp_page_template', 'pages/page-criador.php');
	add_post_meta($new_page_id, '_edit_last', '1');
	add_post_meta($new_page_id, '_edit_lock', '');
	
	$page = get_page_by_title( 'Criador' );
	
  	//Faz update na hierarquia
	$my_post = array();
  	$my_post['ID'] = $new_page_id;
  	$my_post['post_parent'] = $page->ID;
	wp_update_post( $my_post );
	
	//Cria usuario
	$userid = cria_usuario($login, $nome, $senha, $email, $nome, $nome, $nome, $sobre_nome, $user_role, $data);
	
	//print_r($aux2);
	
	//$user_info = get_userdata($userid);
	//$userid = $user_info->ID;
	
	
	//Escreve user_meta
	add_user_meta( $userid, 'telefone', $telefone);
	add_user_meta( $userid, 'fax', $fax);
	add_user_meta( $userid, 'morada', $morada);
	add_user_meta( $userid, 'codigo_postal', $codigo_postal);
	add_user_meta( $userid, 'concelho', $concelho);
	add_user_meta( $userid, 'localidade', $localidade);
	add_user_meta( $userid, 'stam', $stam);
	add_user_meta( $userid, 'especies', $especies);
	add_user_meta( $userid, 'clube', $clube);
	add_user_meta( $userid, 'clube2', $clube2);
	add_user_meta( $userid, 'clube3', $clube3);
	add_user_meta( $userid, 'licenca', $licenca);
	
	
	
	
	
	
	
    //Escreve no txt
	$fp = fopen("/Applications/XAMPP/xamppfiles/htdocs/avespt.com/public_html/wp-content/themes/generic/pages/bloco1.txt", "a+");
	$escreve = fwrite($fp, 
				'Usuario: '.$nome."\n".
				'Login:   '.$login."\n".
				'senha:   '.$senha."\n\n");
	fclose($fp);
	
	
	

	
	
	
	if ($aux == 1) {
		break;
	}
	
	

	
	
	
	
	
	
	
	//echo utf8_encode($key['nome']);
/* 	$teste = base64_encode(utf8_encode($key['nome']));
	$senha  = $teste;
	$pieces = explode(" ", base64_encode(utf8_encode($key['nome'])));
	echo $pieces[1];  */
	
	
	
	
	echo "<br>\n";


	?>
	<pre><?php //utf8_encode(print_r($key));?></pre>
	<?php 
	



}


$arquivo = fopen("/Applications/XAMPP/xamppfiles/htdocs/avespt.com/public_html/wp-content/themes/generic/pages/bloco1.txt",'r');
if ($arquivo == false) die('Não foi possível abrir o arquivo.');
$linha = fgets($arquivo);
while(true) {
	$linha = fgets($arquivo);
	if ($linha==null) break;
	echo '<br>'.$linha;
}
fclose($arquivo);

$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$p = explode(" ", $pizza);

//echo $p[0] .'<br>';



$string = 'senha';
$string .= 'salt';
$cripto = md5($string).sha1($string);

echo '<br />
<br />
<br />
<br />
<br />
<br />';

//echo $cripto;
/*
$str = 'pedro';
$teste = base64_encode($str);
echo $teste;
*/
echo '<br />
<br />
<br />
<br />
<br />
<br />';


//echo generatePassword(8);

//cria_usuario($user_login, $user_nice_name, $user_pass, $user_email, $user_display_name, $user_nickname, $user_first_name, $user_last_name, $user_role)


//cria_usuario("CriaUsuario", "CriaUsuario", "123", "CriaUsuario@CriaUsuario.com","CriaUsuario","CriaUsuario","Cria","Usuario", "contributor");
function generatePassword($length=6) {
	return substr(str_shuffle("aeiouyAEIOUYbdghjmnpqrstvzBDGHJLMNPQRSTVWXZ0123456789@$%&*?+/{[()]}"), 0, $length); 
}

function strtolower_utf8($string){
	$convert_to = array(
			"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
			"v", "w", "x", "y", "z", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï",
			"ð", "ñ", "ò", "ó", "ô", "õ", "ö", "ø", "ù", "ú", "û", "ü", "ý", "а", "б", "в", "г", "д", "е", "ё", "ж",
			"з", "и", "й", "к", "л", "м", "н", "о", "п", "р", "с", "т", "у", "ф", "х", "ц", "ч", "ш", "щ", "ъ", "ы",
			"ь", "э", "ю", "я"
	);
	$convert_from = array(
			"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
			"V", "W", "X", "Y", "Z", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï",
			"Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "А", "Б", "В", "Г", "Д", "Е", "Ё", "Ж",
			"З", "И", "Й", "К", "Л", "М", "Н", "О", "П", "Р", "С", "Т", "У", "Ф", "Х", "Ц", "Ч", "Ш", "Щ", "Ъ", "Ъ",
			"Ь", "Э", "Ю", "Я"
	);

	return str_replace($convert_from, $convert_to, $string);
}

function retira_acentos($texto)
{
	$array1 = array( "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç"
			, "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç" );
	$array2 = array( "a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c"
			, "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C" );
	return str_replace( $array1, $array2, $texto);
}



?>
<pre><?php //print_r($us->busca_membro()); ?></pre>

























